package com.example.home;

import java.util.HashMap;
/**
code 200 成功
code 201 参数错误
code 202
* */
public class BRespond {
    public static Object respond_success(Object data){
        return  respond_success_message(data,"");
    }
    public  static Object respond_success_message(Object data,String message){
        HashMap<String,Object> result = new HashMap<>();
        result.put("result",data);

        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("code",BEnumRespond.success.getCode());
        hashMap.put("message",message.length() > 0 ? message : BEnumRespond.success.getMessage());
        hashMap.put("data",result);
        return hashMap;
    }
    public static Object respond_failure(BEnumRespond code){
        return respond_failure_message(code.getCode(),code.getMessage());
    }
    public static Object respond_failure_message(int code,String message){
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("code",code);
        hashMap.put("message",message);
        return hashMap;
    }
}
